<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<div class="aui-fullpage">
    <div class="aui-header-1">
        <lv-group lvGutter="8px">
            <i lv-icon="aui-widget-datepicker-previous" [lvColorState]="true" (click)="gotoRecoveryDrill()"></i>
            <h1>{{ drillPlan?.name | nil }}</h1>
        </lv-group>
    </div>
    <div class="overview">
        <lv-group [lvColumns]='["54%", "46%"]' class="drill-content-group">
            <lv-group [lvColumns]='["220px", "auto"]' class="base-info-group">
                <div class="overview-clock"></div>
                <div class="drill-detail">
                    <h2>{{drillPlan?.name | nil}}</h2>
                    <aui-status [value]="drillPlan?.status" type="drillStatus"></aui-status>
                    <lv-group class="base-form" lvGutter='40px'>
                        <lv-group lvDirection='vertical' lvGutter='4px'>
                            <span class="small-font">{{'explore_drill_plan_type_label' | i18n}}</span>
                            <span>{{drillPlan?.type | textMap:'drillType'}}</span>
                        </lv-group>
                        <lv-group lvDirection='vertical' lvGutter='4px'>
                            <span class="small-font">{{'explore_drill_period_label' | i18n}}</span>
                            <span>
                                <ng-container
                                    *ngIf="drillPlan?.type === dataMap.drillType.period.value; else elseTemplate">
                                    <ng-container *ngIf="_isEn">
                                        {{drillPlan.interval}}&nbsp;{{drillPlan.intervalUnit |
                                        textMap:'recoveryDrillUnit'}}
                                    </ng-container>
                                    <ng-container *ngIf="!_isEn">
                                        {{drillPlan.interval}}{{drillPlan.intervalUnit |
                                        textMap:'recoveryDrillUnit'}}
                                    </ng-container>
                                </ng-container>
                                <ng-template #elseTemplate>
                                    --
                                </ng-template>
                            </span>
                        </lv-group>
                        <lv-group lvDirection='vertical' lvGutter='4px'>
                            <span class="small-font">{{'explore_recent_result_label' | i18n}}</span>
                            <span>
                                <aui-status [value]="drillPlan?.recentJobStatus" type="Job_status"></aui-status>
                            </span>
                        </lv-group>
                    </lv-group>
                    <div style="margin-top: 15px;">
                        <lv-operation-menu [lvItemsFn]="optsCallback" [lvData]="drillPlan"></lv-operation-menu>
                    </div>
                </div>
            </lv-group>
            <lv-group lvGutter='80px' class="base-info-group" style="height: 80px;">
                <lv-group lvDirection='vertical' lvGutter='14px'>
                    <span class="info-title">{{'explore_drill_numbers_label' | i18n}}</span>
                    <h2 class="big-font">{{drillPlan?.executeCount | nil}}</h2>
                </lv-group>
                <div class="group-line"></div>
                <lv-group lvDirection='vertical' lvGutter='14px'>
                    <span class="info-title">{{'explore_drill_success_rate_label' | i18n}}</span>
                    <h2 lv-overflow class="big-font">
                        <ng-container *ngIf="_isNumber(drillPlan?.successRate); else elseTemplate">
                            {{_round(drillPlan?.successRate*100)}}<span class="percent-font">%</span>
                        </ng-container>
                    </h2>
                </lv-group>
                <div class="group-line"></div>
                <lv-group lvDirection='vertical' lvGutter='14px'>
                    <span class="info-title">{{'explore_previous_recovery_time_label' | i18n}}</span>
                    <h2 lv-overflow class="big-font">
                        <ng-container *ngIf="_isNumber(drillPlan?.averageTime); else elseTemplate">
                            {{appUtilsService.getDuration(drillPlan?.averageTime*1000) | nil}}
                        </ng-container>
                    </h2>
                </lv-group>
            </lv-group>
        </lv-group>
    </div>
    <div class="summary-info aui-block">
        <lv-tabs (lvActiveIndexChange)="indexChange($event)">
            <lv-tab lvTitle="{{'common_basic_info_label' | i18n}}" lvId='basic'>
                <h3 class="aui-gutter-column-lg">{{'explore_drill_object_label' | i18n}}</h3>
                <lv-pro-table #basicInfoTable [config]="basicInfoTableConfig"
                    [data]="basicInfoTableData"></lv-pro-table>
            </lv-tab>
            <lv-tab lvTitle="{{'common_execute_result_label' | i18n}}" lvId='result'>
                <div class="list-container">
                    <button lv-button class="aui-gutter-column-sm" [disabled]="!resultTableData?.data?.length"
                        (click)="exportJob()">
                        {{'common_download_all_label' | i18n}}
                    </button>
                    <lv-pro-table #resultTable [config]="resultTableConfig" [data]="resultTableData"></lv-pro-table>
                </div>
            </lv-tab>
        </lv-tabs>
    </div>
</div>

<ng-template #elseTemplate>
    --
</ng-template>

<ng-template #startTimeTpl let-item>
    <span lv-overflow class="aui-link" (click)="executeDetail(item)">
        {{item.startTime | date: 'yyyy-MM-dd HH:mm:ss':timeZone | nil}}
    </span>
</ng-template>

<ng-template #endTimeTpl let-item>
    <span lv-overflow>{{item.endTime | date: 'yyyy-MM-dd HH:mm:ss':timeZone | nil}}</span>
</ng-template>

<ng-template #resourceType let-item>
    <span lv-overflow>{{getResourceType(item) | nil}}</span>
</ng-template>

<ng-template #drillTypeTpl let-item>
    <span lv-overflow>
        {{item.type | textMap:'recoveryDrillType'}}
    </span>
</ng-template>

<ng-template #destroyTpl let-item>
    <ng-container *ngIf="item.type === dataMap.recoveryDrillType.liveMount.value; else elseTemplate">
        <span lv-overflow>{{item.shouldDestroy | textMap:'drillMountConfig'}}</span>
    </ng-container>
</ng-template>